package app.ui;

import java.util.List;
import java.util.concurrent.ExecutionException;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import database.local.Business;
import database.local.DataBaseClient;
import database.local.Deal;

public class listActivity extends Activity {
	private List<Business> list;
	private String type;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_tab_layout);
		
		//get extras 
		Bundle b = getIntent().getBundleExtra("values");
		type = b.getString("type");
		list = b.getParcelableArrayList("list");
		
		//open the list
		ListView lv1 = (ListView) findViewById(android.R.id.list);
		lv1.setAdapter(new BusinessListArrayAdapter(this, list));
		lv1.setOnItemClickListener( new AdapterView.OnItemClickListener() {

			public void onItemClick(AdapterView<?> parentView, View childView, int position,
					long id) {
				openDealWindow(list.get(position), list.get(position).getDeals().get(0));
			}
		});
	
	}

	protected void openDealWindow(Business b, Deal d) {
		Intent openDealActivity = new Intent(this, DealViewActivity.class);
		Bundle bundle = new Bundle();
		
		bundle.putParcelable("deal", d);
		bundle.putParcelable("business", b);
		
		openDealActivity.putExtra("values", bundle);
		this.startActivity(openDealActivity);
		
	}
}
